package com.yoda.youdianda.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yoda.youdianda.common.R;
import com.yoda.youdianda.domain.YddAdvpos;
import com.yoda.youdianda.service.YddAdvposService;
import com.yoda.youdianda.vo.PageResult;
import com.yoda.youdianda.vo.YddAdvposVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ydd_advpos")
@Slf4j
public class YddAdvposController {
    @Autowired
    private YddAdvposService yddAdvposService;

    //分页,搜索
    @GetMapping("/list")
    public R<PageResult<YddAdvposVo>> page(String advposdesc, String advposname, int page, int limit) {
        //调用Service层方法,返回Page对象
        PageResult<YddAdvposVo> advposPage = yddAdvposService.getPage(advposdesc, advposname, page, limit);
        return R.success(advposPage, 0);
    }

    //数据回显
    @GetMapping("/rowInfo")
    public R<YddAdvposVo> getById(Long id) {
        YddAdvposVo yddAdvposVo = yddAdvposService.getYddadvposVo(id);
        return R.success(yddAdvposVo, 0);
    }

    //修改数据
    @PostMapping("/update")
    public R<String> update(@RequestBody YddAdvpos yddAdvpos) {
        yddAdvposService.updateById(yddAdvpos);
        return R.success("修改成功", 0);
    }

    @GetMapping("/del")
    public R<String> del(int id) {
        yddAdvposService.delById(id);
        return R.success("删除成功", 0);
    }

    @GetMapping("/all")
    public R<List<YddAdvpos>> getAll() {
        return R.success(yddAdvposService.list(), 0);
    }

    @PostMapping("/add")
    public R<String> add(@RequestBody YddAdvpos yddAdvpos) {
        boolean res = yddAdvposService.addAdvPos(yddAdvpos);
        return R.success("添加成功", 0);
    }
}
